﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FBWMS.Properties;
using FBWMS;
using  FBWMS.DataBase;
using System.Drawing.Imaging;
using CrystalDecisions.CrystalReports.Engine;
using System.Reflection;


namespace FBWMS
{
    public partial class F_LGELabelDataEntry : Form
    {
        public F_LGELabelDataEntry()
        {
            InitializeComponent();
        }

        #region"Variable"

        private DataTable dt_Header;
        private DataTable dt_Detail;



        #endregion

        #region "Command Mehtods"

        private void P_Clear_Detail()
        {
            this.txt_LGEP_NO.Text = string.Empty;
            this.txt_MakerP_NO.Text = string.Empty;
            this.txt_Lot_NO.Text = string.Empty;
            this.txt_SEQ_NO.Text = string.Empty;
            this.txt_QTY.Text = string.Empty;

            this.lb_GP_NO.Text = "";
            this.lb_GPPOS_NO.Text = "";
            this.lb_Hidden_ID.Text = "";
        }

        private void P_Clear_Header()
        {
            this.tgl_Regist.Checked = false;
            this.tgl_Edit.Checked = false;
            this.tgl_Delete.Checked = false;

            this.txt_GP_NO_Search.Text = string.Empty;
            this.txt_GP_NO.Text = string.Empty;

            this.fpSpread1.ActiveSheet.RowCount = 0;
            if (dt_Header != null)
            {
                dt_Header.Clear();
            }

            if (dt_Detail != null)
            {
                dt_Detail.Clear();
            }
        }

        private void P_SetEnable_Detail(bool bEnabled)
        {
            this.txt_LGEP_NO.Enabled = bEnabled;
            this.txt_MakerP_NO.Enabled = bEnabled;
            this.txt_Lot_NO.Enabled = bEnabled;
            this.txt_SEQ_NO.Enabled = bEnabled;
            this.txt_QTY.Enabled = bEnabled;

            this.btn_Add.Enabled = bEnabled;
            this.btn_Modify.Enabled = bEnabled;
            this.btn_Detail_Clear.Enabled = bEnabled;
            this.fpSpread1.Enabled = bEnabled;

        }

        private void P_SetEnabled_Header(bool bEnabled)
        {
            this.txt_GP_NO.Enabled = bEnabled;
        }

        private void P_Clear_AddFinish()
        {
            this.txt_Lot_NO.Text = string.Empty;
            this.txt_SEQ_NO.Text = string.Empty;
            this.txt_QTY.Text = string.Empty;

            this.lb_GP_NO.Text = "";
            this.lb_GPPOS_NO.Text = "";
            this.lb_Hidden_ID.Text = "";
            this.txt_Lot_NO.Focus();
        }

        private void P_InitDisplay_ByMode(string str_Mode)
        {
            string str_Message = string.Empty;
            string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);

            P_Clear_Detail();

            this.txt_GP_NO_Search.Text = string.Empty;
            this.txt_GP_NO.Text = string.Empty;

            this.fpSpread1.ActiveSheet.RowCount = 0;
            if (dt_Header != null)
            {
                dt_Header.Clear();
            }

            if (dt_Detail != null)
            {
                dt_Detail.Clear();
            }

            switch (str_Mode)
            {
                case "Entry"://登録

                    this.btn_Update.Enabled = true;
                    this.btn_Print.Enabled = true;
                    P_SetEnabled_Header(true);
                    P_SetEnable_Detail(true);
                    this.btn_Modify.Enabled = false;
                    this.panel_Search.Enabled = false;
                    this.txt_GP_NO.Focus();

                    break;
                case "Mod"://変更

                    this.btn_Update.Enabled = false;
                    this.btn_Print.Enabled = false;
                    this.P_SetEnabled_Header(false);
                    this.P_SetEnable_Detail(true);
                    this.panel_Search.Enabled = true;
                    this.btn_Modify.Enabled = false;
                    this.txt_LGEP_NO.Focus();

                    break;

                case "Del"://削除
                    this.btn_Update.Enabled = false;
                    this.btn_Print.Enabled = false;
                    this.panel_Search.Enabled = true;
                    this.P_SetEnabled_Header(false);
                    this.P_SetEnable_Detail(false);
                    break;

                default:
                    break;
            }


        }

        private bool P_Detail_Update_Check()
        {
            string strCaption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);

            if (this.txt_GP_NO.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_GroupIDIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_GP_NO.Focus();
                return false;
            }

            if (this.txt_LGEP_NO.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_LGEPNOIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_LGEP_NO.Focus();
                return false;
            }

            if (this.txt_MakerP_NO.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_MakerPNOIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_MakerP_NO.Focus();
                return false;
            }

            if (this.txt_Lot_NO.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_LotNoIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_Lot_NO.Focus();
                return false;
            }

            if (this.txt_QTY.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_QTYIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_QTY.Focus();
                return false;
            }

            if (Convert.ToInt32(this.txt_QTY.Text.Trim()) <= 0)
            {
                MessageBox.Show(Resources.Msg_QTYError, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_QTY.Focus();
                return false;
            }

            return true;
        }

        private bool P_Detail_DataUpdate(string str_Model, string str_ID)
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                string str_GP_NO = this.txt_GP_NO.Text.Trim();
                string str_GPPOS_NO = "0";

                if (this.lb_GPPOS_NO.Text.Trim().Length > 0)
                {
                    str_GPPOS_NO = this.lb_GPPOS_NO.Text.Trim();
                }
                string str_LGEP_NO = this.txt_LGEP_NO.Text.Trim();
                string str_MakerP_NO = this.txt_MakerP_NO.Text.Trim();
                string str_Lot_NO = this.txt_Lot_NO.Text.Trim();
                string str_SEQ_NO = this.txt_SEQ_NO.Text.Trim();
                string str_QTY = this.txt_QTY.Text.Trim();
                if (str_QTY == "")
                {
                    str_QTY = "0";
                }
                string str_PC_NM = G_CommonDefine.G_PCNM;
                string str_ErrMessage = "";
                int result = G_CommonClassBussniss.G_F_LGELabelDataEntry_Sub_Update(str_Model, str_ID, str_GP_NO, str_GPPOS_NO, str_LGEP_NO, str_MakerP_NO, str_Lot_NO, str_SEQ_NO, str_QTY, str_PC_NM, ref str_ErrMessage);


                switch (result)
                {
                    case 0:
                        break;
                    default:
                        //str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Double_POSNo);
                        MessageBox.Show(str_ErrMessage, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                        break;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return true;
        }

        private void P_BindDataGrid(FarPoint.Win.Spread.SheetView sheet, DataTable dt)
        {

            if ((dt == null) || (dt.Rows.Count == 0))
            {
                sheet.RowCount = 0;
                return;
            }

            sheet.RowCount = dt.Rows.Count;


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];

                sheet.Cells[i, 0].Tag = Convert.ToString(row["ID"]);
                sheet.Cells[i, 1].Tag = Convert.ToString(row["ID"]);
                sheet.Cells[i, 2].Value = row["LGEP_NO"].ToString();
                sheet.Cells[i, 3].Value = row["MakerP_NO"].ToString();
                sheet.Cells[i, 4].Value = row["Lot_NO"].ToString();
                sheet.Cells[i, 5].Value = row["SEQ_NO"].ToString();
                sheet.Cells[i, 6].Value = row["QTY"].ToString();
                //sheet.Cells[i, 7].Value = row["JAN_CD"].ToString();
                sheet.Cells[i, 7].Value = row["GP_NO"].ToString();
                sheet.Cells[i, 8].Value = row["GPPOS_NO"].ToString();
            }
        }

        private void P_Sub_CellClick(string str_Mode, string str_ID)
        {

            try
            {
                int int_Row = 0;//Error
                DataRow[] Rows = this.dt_Detail.Select("ID=" + str_ID + "");
                if (Rows.Length == 0)
                {
                    return;
                }
                switch (str_Mode)
                {
                    case "Select"://SELECT

                        this.lb_Hidden_ID.Text = Rows[int_Row]["ID"].ToString();
                        this.lb_GP_NO.Text = Rows[int_Row]["GP_NO"].ToString();
                        this.lb_GPPOS_NO.Text = Rows[int_Row]["GPPOS_NO"].ToString();
                        this.txt_LGEP_NO.Text = Rows[int_Row]["LGEP_NO"].ToString();
                        this.txt_MakerP_NO.Text = Rows[int_Row]["MakerP_NO"].ToString();
                        this.txt_Lot_NO.Text = Rows[int_Row]["Lot_NO"].ToString();
                        this.txt_SEQ_NO.Text = Rows[int_Row]["SEQ_NO"].ToString();
                        this.txt_QTY.Text = Rows[int_Row]["QTY"].ToString();

                        this.btn_Add.Enabled = false;
                        this.btn_Modify.Enabled = true;

                        break;

                    case "Delete"://DELETE


                        P_Detail_DataUpdate("2",str_ID);

                        //this.P_Clear_AddFinish();

                        dt_Detail = G_CommonClassBussniss.G_F_LGELabelDataEntry_GetData_Sub(G_CommonDefine.G_PCNM);

                        P_BindDataGrid(this.fpSpread1.ActiveSheet, dt_Detail);
                        break;
                }
            }
            catch (Exception err)
            {

                MessageBox.Show(err.Message);
            }
        }

        private bool P_Check_Update()
        {
            string strCaption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);

            if (this.txt_GP_NO.Text.Trim().Length == 0)
            {
                MessageBox.Show(Resources.Msg_GroupIDIsBlank, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_GP_NO.Focus();
                return false;
            }

            if (this.fpSpread1.ActiveSheet.RowCount == 0)
            {
                MessageBox.Show(Resources.msg_DetailIsBland, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_LGEP_NO.Focus();
                return false;
            }

            if ((dt_Detail == null) || (dt_Detail.Rows.Count == 0))
            {
                MessageBox.Show(Resources.msg_DetailIsBland, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txt_LGEP_NO.Focus();
                return false;
            }
            return true;
        }

        private bool P_Update_DataUpdate(string str_Mode,bool isPrinter)
        {

            string str_Message = string.Empty;
            string str_Caption = string.Empty;

            try
            {
                string str_ErrMsg ="";

                int reuslt = G_CommonClassBussniss.G_F_LGELabelDataEntry_DataUpdate(str_Mode, this.txt_GP_NO.Text, ref str_ErrMsg);

                switch (reuslt)
                {
                    case -1:
                        str_Message = Resources.msg_GroupIDExists;

                        MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.txt_GP_NO.Enabled = true;
                        this.txt_GP_NO.Focus();
                        return false;
                        break;
                    case 0:
                        if (isPrinter == false)
                        {
                            if (this.tgl_Regist.Checked == true)
                            {
                                str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_InsertSuccess);
                            }
                            else
                            {
                                str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_UpdateSuccess);
                            }
                            str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                            MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        break;
                    default:
                        str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_UpdateFail);
                        str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                        MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);

                        return false;
                        break;
                }
            }
            catch (Exception err)
            {

                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                MessageBox.Show(err.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }

        private void P_Update()
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            
            string str_Mode;

            if (this.tgl_Regist.Checked)
            {
                str_Mode = "0";
            }
            else if (this.tgl_Edit.Checked)
            {
                str_Mode = "1";
            }
            else 
            {
                str_Mode = "2";
            }

            //DB更新
            if (!this.P_Update_DataUpdate(str_Mode,false))
            {
                return;
            }

            this.btn_Clear.PerformClick();
        }

        private void P_Printer()
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;

            string str_Mode;

            if (this.tgl_Regist.Checked)
            {
                str_Mode = "0";
            }
            else if (this.tgl_Edit.Checked)
            {
                str_Mode = "1";
            }
            else
            {
                str_Mode = "2";
            }

            //DB更新
            if (!this.P_Update_DataUpdate(str_Mode,true))
            {
                return;
            }

            DataTable dtLabel = G_CommonClassBussniss.G_F_LGELabelDataEntry_Print_GetData(this.txt_GP_NO.Text.Trim());

            if ((dtLabel != null) && (dtLabel.Rows.Count > 0))
            {
                ds_LGELabel ds_LGELabelData = G_CommonClassBussniss.G_PrintLGELabel(dtLabel);

                Assembly asm = Assembly.GetExecutingAssembly();
                Type t;
                Object obj;
                ReportDocument rpt;
                t = asm.GetType("FBWMS.Report." + "R_LGELabel");
                obj = t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
                rpt = (ReportDocument)(obj);
                rpt.SetDataSource((DataSet)ds_LGELabelData);
                rpt.PrintOptions.PrinterName = this.cmb_Printer.Text.Trim();
                rpt.PrintToPrinter(1, true, 0, 0);

                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);
                MessageBox.Show(Resources.msg_PrintFinish, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);
                MessageBox.Show(Resources.msg_NotDataForPrint, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.btn_Clear.PerformClick();
        }



        private bool P_Search_DataInsert()
        {

            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                string str_GroupID = txt_GP_NO_Search.Text.Trim();
                int reuslt = G_CommonClassBussniss.G_F_LGELabelDataEntry_Insert(str_GroupID, G_CommonDefine.G_PCNM);
                if (reuslt != 0)
                {
                    str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_UpdateFail);
                    str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                    MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
            }
            catch (Exception err)
            {

                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                MessageBox.Show(err.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }

        private void P_Search()
        {


            string str_Message = string.Empty;
            string str_Caption = string.Empty;

            string str_GroupID = this.txt_GP_NO_Search.Text.Trim();

            this.dt_Header = G_CommonClassBussniss.G_F_LGELabelDataEntry_GetData(str_GroupID);


            if ((dt_Header == null) || (this.dt_Header.Rows.Count == 0) || (this.dt_Header.Rows[0]["GP_NO"].ToString().Equals(string.Empty)))
            {
                str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_DataNotExist);
                MessageBox.Show(str_Message);
                return;
            }

            this.txt_GP_NO.Text = dt_Header.Rows[0]["GP_NO"].ToString();

            this.P_Clear_Detail();


            //ワークテーブル生成
            if (!this.P_Search_DataInsert())
            {
                return;
            }

            //ワークテーブルよりサブフォームデータ取得
            //this.uSP_PC_F_Syk_EditSykData_SUB_DataSelectTableAdapter.Fill(this.ds_F_Syk_EditSykData.USP_PC_F_Syk_EditSykData_SUB_DataSelect, G_CommonDefine.G_PCNM);
            //sub datagrid data
            this.dt_Detail = G_CommonClassBussniss.G_F_LGELabelDataEntry_GetData_Sub(G_CommonDefine.G_PCNM);

            P_BindDataGrid(this.fpSpread1.ActiveSheet, this.dt_Detail);

            this.btn_Update.Enabled = true;

            this.txt_GP_NO.Enabled = false;

            if (this.tgl_Edit.Checked)
            {
                //this.panel_HD.Enabled = true;
                //this.panel_BD.Enabled = true;
                this.btn_Print.Enabled = true;
                this.fpSpread1.Enabled = true;
                this.txt_LGEP_NO.Focus();
            }

            this.panel_Search.Enabled = false;
        }

        #endregion

        #region "Command Events"

        private void btn_Clear_Click(object sender, EventArgs e)
        {
            this.P_Clear_Header();
            this.P_Clear_Detail();
            this.panel_Search.Enabled = false;
            this.P_SetEnabled_Header(false);
            this.P_SetEnable_Detail(false);
            this.btn_Update.Enabled = false;
            this.btn_Print.Enabled = false;


        }

        private void btn_Update_Click(object sender, EventArgs e)
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                if (this.tgl_Delete.Checked)
                {
                    str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_ConfirmDelete);
                    str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                    if (DialogResult.Cancel.Equals(MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)))
                    {
                        return;
                    }
                }
                else
                {
                    if (!this.P_Check_Update())
                    {
                        return;
                    }
                    str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_ConfirmUpdate);
                    str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                    if (MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcStart, "btn_Update_Click Start", "btn_Update_Click");
                this.P_Update();
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcEnd, "btn_Update_Click End", "btn_Update_Click");
            }
            catch (Exception ex)
            {
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "btn_Update_Click Error" + ex.Message, "btn_Update_Click");
                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                MessageBox.Show("btn_Update_Click" + ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
         
        }

        private void btn_Print_Click(object sender, EventArgs e)
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                if (this.tgl_Delete.Checked)
                {
                    str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_ConfirmDelete);
                    str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                    if (DialogResult.Cancel.Equals(MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)))
                    {
                        return;
                    }
                }
                else
                {
                    if (!this.P_Check_Update())
                    {
                        return;
                    }
                    str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_ConfirmUpdate);
                    str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                    if (MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        return;
                    }
                }
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcStart, "btn_Update_Click Start", "btn_Update_Click");
                this.Cursor = Cursors.WaitCursor;
                this.P_Printer();
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcEnd, "btn_Update_Click End", "btn_Update_Click");
            }
            catch (Exception ex)
            {
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "btn_Update_Click Error" + ex.Message, "btn_Update_Click");
                str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                MessageBox.Show("btn_Update_Click" + ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void tgl_Regist_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (!this.tgl_Regist.Checked)
                {
                    return;
                }

                this.P_InitDisplay_ByMode("Entry");

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void tgl_Edit_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (!this.tgl_Edit.Checked)
                {
                    return;
                }

                this.P_InitDisplay_ByMode("Mod");

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void tgl_Delete_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (!this.tgl_Delete.Checked)
                {
                    return;
                }

                this.P_InitDisplay_ByMode("Del");

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        private void btn_SelectGroup_NO_Click(object sender, EventArgs e)
        {
            try
            {
                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcStart, "btn_SelectGroup_NO_Click Start", "btn_SelectGroup_NO_Click");

                //FB_NO検索画面を表示する。
                //G_CommonDefine.G_txt_FB_NO = this.txt_sFB_No;


                Form F_COM_Search_GroupID = new F_COM_Search_GroupID();
                F_COM_Search_GroupID.ShowDialog();
                this.txt_GP_NO_Search.Text = G_CommonDefine.G_txt_GroupID.Text;

                //this.txt_FB_NO.Text = G_CommonDefine.G_txt_FB_NO.Text;

                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcEnd, "btn_SelectGroup_NO_Click End", "btn_SelectGroup_NO_Click");
            }
            catch (Exception ex)
            {
                //ログ書込み
                string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "btn_SelectGroup_NO_Click Errpr" + ex.Message, "btn_SelectGroup_NO_Click");

                //エラーメッセージ表示
                MessageBox.Show("btn_SelectGroup_NO_Click" + ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btn_Search_Click(object sender, EventArgs e)
        {

            string str_Message = string.Empty;
            string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
            try
            {
                //FB NOチェック
                if (!G_CommonClassChk.G_Chk_Null(this.txt_GP_NO_Search.Text.Trim()))
                {
                    str_Message = Resources.msg_SetGroupIDForSearch;

                    MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.btn_SelectGroup_NO.Focus();
                    return;
                }

                //待機画面の表示
                G_CommonClassOther.G_Other_WaitForm(true);

                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcStart, "btn_Search_Click Start", "btn_Search_Click");

                //検索処理
                this.P_Search();

                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.ProcEnd, "btn_Search_Click End", "btn_Search_Click");
            }
            catch (Exception ex)
            {
                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "btn_Search_Click Error" + ex.Message, "btn_Search_Click");

                //エラーメッセージ表示
                MessageBox.Show("btn_Search_Click" + ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (G_CommonDefine.G_F_COM_Waiting != null)
                {
                    //待機画面の解除
                    G_CommonClassOther.G_Other_WaitForm(false);
                }
            }
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);
            try
            {
                if (P_Detail_Update_Check() == false)
                {
                    return;
                }

                P_Detail_DataUpdate("0", "0");

                //this.P_Clear_AddFinish();
                this.txt_QTY.Focus();
                dt_Detail = G_CommonClassBussniss.G_F_LGELabelDataEntry_GetData_Sub(G_CommonDefine.G_PCNM);

                P_BindDataGrid(this.fpSpread1.ActiveSheet, dt_Detail);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, str_Caption,MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        private void btn_Modify_Click(object sender, EventArgs e)
        {
            string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Information);
            try
            {
                if (P_Detail_Update_Check() == false)
                {
                    return;
                }

                P_Detail_DataUpdate("1", this.lb_Hidden_ID.Text.Trim());

                this.P_Clear_Detail();

                dt_Detail = G_CommonClassBussniss.G_F_LGELabelDataEntry_GetData_Sub(G_CommonDefine.G_PCNM);

                P_BindDataGrid(this.fpSpread1.ActiveSheet, dt_Detail);

                this.btn_Add.Enabled = true;
                this.btn_Modify.Enabled = false;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btn_Detail_Clear_Click(object sender, EventArgs e)
        {
            this.P_Clear_Detail();
            this.txt_LGEP_NO.Focus();
        }

        private void F_LGELabelDataEntry_Load(object sender, EventArgs e)
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                this.panel_Search.Enabled = false;
                this.P_SetEnabled_Header(false);
                this.P_SetEnable_Detail(false);

                dt_Header = new DataTable();
                dt_Detail = new DataTable();

                this.lb_GP_NO.Text = "";
                this.lb_GPPOS_NO.Text = "";

                G_CommonClassBussniss.G_F_LGELabelDataEntry_WorkerDataDelete(G_CommonDefine.G_PCNM);
                DataTable dt_Print = G_CommonClassBussniss.G_F_Nyk_Inspection_HK_GetPrinterData();
                G_CommonClassPrinter.G_LabelPrinter_ComboSetting(this.cmb_Printer,dt_Print);

                this.fpSpread1.ActiveSheet.Columns[7].Visible = false;
                this.fpSpread1.ActiveSheet.Columns[8].Visible = false;
                this.fpSpread1.ActiveSheet.RowCount = 0;
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void fpSpread1_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
        {
            string str_Message = string.Empty;
            string str_Caption = string.Empty;
            try
            {
                if ((this.fpSpread1.ActiveSheet.Cells[e.Row, e.Column].Tag == null) || (this.dt_Detail == null) || (this.dt_Detail.Rows.Count == 0))
                {
                    return;
                }
                string str_ID = this.fpSpread1.ActiveSheet.Cells[e.Row, e.Column].Tag.ToString();

                switch (e.Column)
                {
                    case 0:
                        P_Sub_CellClick("Select", str_ID);
                        break;
                    case 1:
                        str_Message = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_ConfirmDelete);
                        str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Check);
                        if (DialogResult.Cancel.Equals(MessageBox.Show(str_Message, str_Caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question)))
                        {
                            return;
                        }
                        P_Sub_CellClick("Delete", str_ID);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        #endregion

        #region "Commond Process"

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (this.cc_ShortcutKeyHelper1.PerformClickByKeys(keyData))
            {
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void F_LGELabelDataEntry_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!e.Control)
                {
                    this.SelectNextControl(this.ActiveControl, !e.Shift, true, true, true);
                }
            }
        }
        
        #endregion
    }
}
